
package Navigation;

import java.io.BufferedReader;
import java.io.FileReader;

class TopologyImpl implements ITopology{

	private ICollection coordinateCollection;
	private ICollection crossingCollection;
	private ICollection streetCollection;
	private ICollection linkCollection;
	
    public TopologyImpl(){
    	coordinateCollection = new CoordinateCollectionImpl();
    	crossingCollection = new CrossingCollectionImpl(coordinateCollection);
    	streetCollection = new StreetCollectionImpl(coordinateCollection);
    	linkCollection = new LinkCollectionImpl();
    }

    public void readTopology() {
    	long zstVorher = System.currentTimeMillis();
    	long zstNachher;
    	System.out.println("Loading Crossings");
        String[] crossingFileContent = IO.getFileContent(LoadFromDatabase.FileNames.fileNameCrossings);
        for(int i=0;i<crossingFileContent.length;i++){
        	ITopologyObject crossing = new CrossingTopologyObjectImpl(crossingFileContent[i]);
        	addCrossing(crossing);
        }
        zstNachher = System.currentTimeMillis();
        System.out.println("Finished Loading Crossings in " + ((zstNachher - zstVorher)/1000) + "sec");
        zstVorher = System.currentTimeMillis();
        System.out.println("Loading Streets");
        String[] streetFileContent = IO.getFileContent(LoadFromDatabase.FileNames.fileNameStreets);
        for(int i=0;i<streetFileContent.length;i++){
        	ITopologyObject street = new StreetTopologyObjectImpl(streetFileContent[i]);
        	addStreet(street);
        }
        zstNachher = System.currentTimeMillis();
        System.out.println("Finished Loading Streets in " + ((zstNachher - zstVorher)/1000) + "sec");
        System.out.println("Loading Links");
        zstVorher = System.currentTimeMillis();
        String[] linkFileContent = IO.getFileContent(LoadFromDatabase.FileNames.fileNameLinks);
        for(int i=0;i<linkFileContent.length;i++){
        	ITopologyObject link = new LinkTopologyObjectImpl(linkFileContent[i]);
        	addLink(link);
        }
        zstNachher = System.currentTimeMillis();
        System.out.println("Finished Loading Links in " + ((zstNachher - zstVorher)/1000) + "sec");
    }

    public void setPointsOfInterest(ITopologyObject[] iTopObj) {
        for(int i=0;i<iTopObj.length;i++){
        	setPoint(iTopObj[i]);
        }
    }
    
    private void setPoint(ITopologyObject poi){
    	ITopologyObject[] topologyObjects = getNearestObjects(poi);
    	ITopologyObject nearestObject = getNearestObject(topologyObjects);
    	insertPointOfInterest(nearestObject, poi);
    }
    
    private ITopologyObject[] getNearestObjects(ITopologyObject poi){
    	return null;
    }
    
    private ITopologyObject getNearestObject(ITopologyObject[] objects){
    	return null;
    }
    
    private void insertPointOfInterest(ITopologyObject object, ITopologyObject poi){
    	
    }
    
    private void addCrossing(ITopologyObject crossing){
    	crossingCollection.add(crossing);
    }
    
    private void addLink(ITopologyObject link){
    	linkCollection.add(link);
    }
    
    private void addStreet(ITopologyObject street){
    	streetCollection.add(street);
    }
    
}
